package keke;
import java.util.*;

interface IntegerStack {
	public Integer push(Integer item);
	public Integer pop(); 
	public Integer peek(); 
	public boolean empty(); 
	public int size(); 

}

class ArrayIntegerStack implements IntegerStack {
	private Integer[] arr;
	private int top=0;
	
	public ArrayIntegerStack(int capacity){
		this.arr = new Integer[capacity];
	}
	@Override
	public String toString() {
		return Arrays.toString(arr);
	}
	
	@Override
	public Integer push(Integer item) {
		if(item==null||top==arr.length)
			return null;
		else
		{		
			arr[top++]=item;
			return item;
		}
	}

	@Override
	public Integer pop() {
		if(empty())
			return null;
		else{
			Integer elem = arr[--top];
			return elem;
		}
			
	}

	@Override
	public Integer peek() {
		if(empty())
			return null;
		else
			return arr[top-1];
	}

	@Override
	public boolean empty() {
		if(top==0)
			return true;
		else
			return false;
	}

	@Override
	public int size() {
		return top;
	}

}

public class Main0403 {
	public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int m=in.nextInt();
        IntegerStack stack=new ArrayIntegerStack(n);
        for(int i = 0;i<m;i++){
        	System.out.println(stack.push(in.nextInt()));
        }
        System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
        System.out.println(stack.toString());
        int x=in.nextInt();
        for(int j = 0;j<x;j++){
        	System.out.println(stack.pop());
        }
        System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
        System.out.println(stack.toString());
        in.close();
	}
}
